﻿using System;
using System.Collections.Generic;
using Autodesk.Revit.UI;

namespace RevitInteractiveUtility.ExternalEventManager
{
	internal class ExternalEventHandler : IExternalEventHandler
	{
		public bool IfOnly
		{
			get
			{
				return this.m_bIfOnly;
			}
			set
			{
				this.m_bIfOnly = value;
			}
		}

		internal void ReSetRequestList()
		{
			this.m_lstRequest = new List<IRequest>();
		}

		internal void AppendRequest(IRequest appendValue)
		{
			this.m_lstRequest.Add(appendValue);
		}

		internal ExternalEventRequest RequestGeter
		{
			get
			{
				return this.m_RequestGeter;
			}
		}

		public void Execute(UIApplication app)
		{
			int num = this.RequestGeter.Take();
			foreach (IRequest request in this.m_lstRequest)
			{
				if (request.RequestId == num)
				{
					request.DoRequest(ExternalEventData.LstInputValue[num]);
					if (this.m_bIfOnly)
					{
						ExternalEventData.LstInputValue[num] = null;
						break;
					}
				}
			}
			ExternalEventData.LstInputValue[num] = null;
		}

		public string GetName()
		{
			return string.Empty;
		}

		private List<IRequest> m_lstRequest = new List<IRequest>();

		private bool m_bIfOnly;

		private ExternalEventRequest m_RequestGeter = new ExternalEventRequest();
	}
}
